
<style>
	th {
		text-align: center;
	}
	
	.table>tbody>tr>td {
		line-height: 50px;
		text-align: center;
		height:60px;
		margin: 0px;
	}
	

	
</style>
<div id="data_page" class="in_page">
	
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get" name="keyword" id="keyword">
					<div class="form-group">
					Api
					</div>
					<div class="form-group" style="float: right;">
						<button type="button" class="btn btn-sm btn-primary link" onclick="addNewManager(this)">添加接口</button>
					</div>
				</form>
			</div>
		</div>
		
	<table class="table table-striped table-bordered table-condensed  ">
		<thead>
			<tr>
				<th width="120px">提交方式</th>
				<th width="120px">接口名</th>
				<th>参数</th>
				<th>说明</th>
				<th width="50px">操作</th>

			</tr>
		</thead>
		<tbody>	
			<volist name="list" id="li">			
				<tr>
					<td>{$li.model}</td>
					<td>{$li.name}</td>
					<td>{$li.param}</td>
					<td>{$li.ds}</td>
					<td width="120px">
					<button type="button" class="btn btn-sm btn-success up" did="{$li.id}">修改</button>
					<button type="button" class="btn btn-sm btn-danger link" link="{:U('Api/del_api')}?id={$li.id}">删除</button>
					</td>
				</tr>
				
			</volist>
		</tbody>
	</table>

<div class="modal fade" id="user-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		 <div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">添加接口</h4>
			</div>
			<div class="modal-body">
				<form id="bjy-form" class=" form-horizontal"  method="post">
					
					<div class="form-group">
					 <label for="title" class="col-sm-2 control-label" > 提交方式:</label>
						<div class="col-sm-3">
							<select class="form-control" id="model">
								<option value="GET">GET</option>
								<option value="POST">POST</option>
							</select>
						</div>
					</div>
					<div class="form-group">
					 <label for="title" class="col-sm-2 control-label" > 接口名:</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" id="name" />
						</div>
					</div>
					
					<div class="form-group">
					 <label for="title" class="col-sm-2 control-label" > 参数:</label>
						<div class="col-sm-6">
							<textarea type="text" class="form-control" id="param" > </textarea>
						</div>
					</div>
					
					<div class="form-group">
					 <label for="title" class="col-sm-2 control-label" > 说明:</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" id="ds" />
						</div>
					</div>
					
					<div class="form-group">
					 <div class="col-sm-offset-2 col-sm-10">
						 <button type="button" class="btn btn-primary button">提交</button>
					</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
</div>
<script language="javascript">



function addNewManager(obj){
	$('#user-add').modal('show');
}




 $(".button").click(function(){
	 	var model = $('#model').val();
	 	var name = $('#name').val();
	 	var param = $('#param').val();
	 	var ds = $('#ds').val();
	 	
	 	var url = "{:U('Api/add_api')}"
	 	var parm = {
	 		model:model,
	 		name:name,
	 		param:param,
	 		ds:ds,
	 	}
	 	
	 	$.post(url,parm,function(obj){
	 		if(obj.s){
	 			alert(obj.m);
	 			location.href="{:U('Api/index')}";
	 		}
	 	})
	 	
	 	
	 })

$(".up").click(function(){
	 	$('#user-add').modal('show');
	 	var id = $(this).attr('did');
	 	
	 	var url = "{:U('Api/api_up')}"
	 	var parm = {	
	 		id:id,
	 	}
	 	$.post(url,parm,function(obj){
	 		if(obj.s){
	 		 var data=obj.d;
	 			 $('#model').val(data.model);
			 	 $('#name').val(data.name);
			 	 $('#param').val(data.param);
			 	 $('#ds').val(data.ds);
			 	 $('.button').removeClass("button").addClass("upbutton").text("修改").attr("did",data.id);
			 	 up();
	 		}
	 	})
	 	
	 	
	 })

function up(){
 $(".upbutton").unbind().bind("click",function(){
	 	var model = $('#model').val();
	 	var name = $('#name').val();
	 	var param = $('#param').val();
	 	var ds = $('#ds').val();
	 	var id = $(this).attr("did"); 	
	 	var url = "{:U('Api/up_api')}"
	 	var parm = {
	 		model:model,
	 		name:name,
	 		param:param,
	 		ds:ds,
	 		id:id,
	 	}
	 	$.post(url,parm,function(obj){
	 		if(obj.s){
	 			alert(obj.m);
	 			location.href="{:U('Api/index')}";
	 		}else{
	 			alert(obj.m);
	 			location.href="{:U('Api/index')}";
	 		}
	 	})
	 	
	 	
	 })
}


</script>